#include <QLabel>
#include <QVBoxLayout>
#include <QPushButton>

#include "aboutdialog.h"

AboutDialog::AboutDialog(QWidget *parent, const QString &title, const QString &version)
	: QDialog(parent)
{
	setAttribute(Qt::WA_DeleteOnClose);
	setWindowTitle(title);
	setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);

	auto vbox = new QVBoxLayout;

	auto label = new QLabel(this);
	QPixmap pm(QString(":/res/tonghao.png"));
	if (!pm.isNull())
		label->setPixmap(pm);
	vbox->addWidget(label);

	auto hbox = new QHBoxLayout;
	vbox->addLayout(hbox);

	{
		auto label = new QLabel(this);
		QPixmap pm(QString(":/res/qtitan.png"));
		if (!pm.isNull())
			label->setPixmap(pm);
		hbox->addWidget(label);
	}

	auto vbox2 = new QVBoxLayout;
	hbox->addLayout(vbox2);

	QString caption = tr(
		"<h3>上海同豪土木工程咨询有限公司</h3>"
		"<h3>%1软件</h3>"
		"<p>版本 %2</p>"
		"<p>程序设计：陈德平</p>")
		.arg(title)
		.arg(version);
	label = new QLabel(this);
	label->setText(caption);
	vbox2->addWidget(label);

	QString translatedTextAboutQtText = tr(
		"<p>版权 (c) 2020-2099 版权所有，盗版违法。</p>");
	label = new QLabel(this);
	label->setText(translatedTextAboutQtText);
	vbox2->addWidget(label);

	{
		auto hbox = new QHBoxLayout;
		hbox->addStretch(1);
		auto btn = new QPushButton;
		btn->setDefault(true);
		btn->setText(tr("确定"));
		connect(btn, &QPushButton::clicked, this, &QDialog::close);
		hbox->addWidget(btn);
		vbox2->addLayout(hbox);
	}

	setLayout(vbox);
}

AboutDialog::~AboutDialog()
{
}
